@extends('layouts.seller')

@section('title', '已卖出的宝贝')

@section('scripts')
    <script src="{{asset('DatePicker/WdatePicker.js')}}"></script>
    <script type="text/javascript">
        var $CONFIG = {
            tab:'{{$tab}}',
            uid:'{{$uid}}',
            username:'{{$username}}'
        }
    </script>
@stop

@section('content')
    <div class="navigation">
        <a>我是卖家</a>
        <span>></span>
        <a>宝贝管理</a>
        <span>></span>
        <a>已卖出的宝贝</a>
    </div>
    <div class="order-search">
        <form method="get" id="searchForm">
            <div class="row">
                <div class="cell">
                    <label>订单编号:</label>
                    <div class="field"><input title="" type="text" class="form-control w200" name="order_no" value="{{$order_no}}"></div>
                </div>
                <div class="cell">
                    <label>买家昵称:</label>
                    <div class="field"><input title="" type="text" class="form-control w200" name="buyer_name" value="{{$buyer_name}}"></div>
                </div>
                <div class="cell">
                    <label>支付方式:</label>
                    <div class="field">
                        <select title="" class="form-control w200" name="pay_type">
                            <option value="0">全部</option>
                            <option value="1"{{$pay_type==1 ? ' selected="selected"' : ''}}>在线支付</option>
                            <option value="2"{{$pay_type==2 ? ' selected="selected"' : ''}}>货到付款</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="cell">
                    <label>物流状态:</label>
                    <div class="field">
                        <select title="" class="form-control w200" name="wuliu_status">
                            <option value="0">全部</option>
                            <option value="4"{{$wuliu_status==4 ? ' selected="selected"' : ''}}>待付款</option>
                            <option value="1"{{$wuliu_status==1 ? ' selected="selected"' : ''}}>未发货</option>
                            <option value="2"{{$wuliu_status==2 ? ' selected="selected"' : ''}}>已发货</option>
                            <option value="3"{{$wuliu_status==3 ? ' selected="selected"' : ''}}>已收货</option>
                        </select>
                    </div>
                </div>
                <div class="cell">
                    <label>宝贝名称:</label>
                    <div class="field"><input title="" type="text" class="form-control w200" name="title" value="{{$title}}"></div>
                </div>
                <div class="cell" style="width: auto;">
                    <label>交易时间:</label>
                    <div class="field">
                        <div class="con"><input title="" type="text" class="form-control w100" name="time_begin" onclick="WdatePicker()" value="{{$time_begin}}"></div>
                        <div class="con">-</div>
                        <div class="con"><input title="" type="text" class="form-control w100" name="time_end" onclick="WdatePicker()" value="{{$time_end}}"></div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="cell">
                    <label></label>
                    <div class="field">
                        <button type="button" class="btn btn-primary" id="search">搜索订单</button>
                        <button type="button" class="btn btn-default" id="export">批量导出</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div class="tabs-container">
        <div class="tabs">
            <div class="tab-item"><a href="{{url('seller/trade/sold?tab=all')}}" class="tab-link{{$tab=='all' ? ' active' : ''}}">全部订单</a></div>
            <div class="tab-item"><a href="{{url('seller/trade/sold?tab=waitPay')}}" class="tab-link{{$tab=='waitPay' ? ' active' : ''}}">等待买家付款</a></div>
            <div class="tab-item"><a href="{{url('seller/trade/sold?tab=waitSend')}}" class="tab-link{{$tab=='waitSend' ? ' active' : ''}}">等待发货</a></div>
            <div class="tab-item"><a href="{{url('seller/trade/sold?tab=send')}}" class="tab-link{{$tab=='send' ? ' active' : ''}}">已发货</a></div>
            <div class="tab-item"><a href="{{url('seller/trade/sold?tab=waitRate')}}" class="tab-link{{$tab=='waitRate' ? ' active' : ''}}">等待买家评价</a></div>
            <div class="tab-item"><a href="{{url('seller/trade/sold?tab=refunding')}}" class="tab-link{{$tab=='refunding' ? ' active' : ''}}">退款中</a></div>
            <div class="tab-item"><a href="{{url('seller/trade/sold?tab=closed')}}" class="tab-link{{$tab=='closed' ? ' active' : ''}}">已关闭的订单</a></div>
        </div>
    </div>
    <div class="content-div">
        <table class="order-title-table" cellpadding="0" cellspacing="0" width="100%">
            <tbody>
            <tr>
                <td>宝贝</td>
                <td width="100">单价</td>
                <td width="80">数量</td>
                <td width="100">买家</td>
                <td width="100">交易状态</td>
                <td width="100">实收款</td>
                <td width="100">操作</td>
            </tr>
            </tbody>
        </table>
        @foreach($orders as $order)
        <div class="order-item-wrap" id="order-item-{{$order['order_id']}}">
            <table class="order-item-table" cellspacing="0" cellpadding="0" width="100%">
                <thead>
                <tr>
                    <th>
                        <span class="wrap-checkbox"><input title="" type="checkbox"></span>
                        <span class="wrap-time">{{@date('Y-m-d H:i', $order['created_at'])}}</span>
                        <span class="wrap-order-no">{{$order['order_no']}}</span>
                    </th>
                    <th colspan="3"></th>
                    <th colspan="3"></th>
                </tr>
                </thead>
                <tbody>
                @foreach($order['items'] as $item)
                <tr>
                    <td class="col1">
                        <div class="goods-pic">
                            <a href="{{item_url($item['itemid'])}}" target="_blank"><img src="{{image_url($item['thumb'])}}"></a>
                        </div>
                        <div style="margin-left: 90px; overflow: hidden;">
                            <div class="goods-name"><a href="{{item_url($item['itemid'])}}" target="_blank">{{$item['title']}}</a></div>
                            <div class="goods-attr">商品属性</div>
                        </div>
                    </td>
                    <td class="col2">
                        @if ($item['promotion_price'])
                            <p><s>￥{{$item['price']}}</s></p>
                            <p>￥{{$item['promotion_price']}}</p>
                        @else
                            <p>￥{{$item['price']}}</p>
                        @endif
                    </td>
                    <td class="col3">{{$item['quantity']}}</td>
                    <td class="col4">
                        @if($loop->first){{$order['buyer_name']}}@endif
                    </td>
                    <td class="col6">
                        @if ($loop->first)
                            @if ($order['trade_status'] == 1)
                                <p>等待买家付款</p>
                                {{--<p><a rel="edit-price" class="link" data-id="{{$order['order_id']}}">修改价格</a></p>--}}
                            @elseif($order['trade_status'] == 2)
                                <p>买家已付款</p>
                            @elseif($order['trade_status'] == 3)
                                <p>宝贝运送中</p>
                                <p>查看物流</p>
                            @elseif($order['trade_status'] == 4)
                                <p>交易成功</p>
                                <p>货物已签收</p>
                            @elseif($order['trade_status'] == 5)
                                <p>交易成功</p>
                                <p>货物已签收</p>
                                <p>买家已评价</p>
                            @elseif($order['trade_status'] == 6)
                                <p><span style="color: #FF0000;">交易关闭</span></p>
                            @endif
                            <p><a href="{{url('/seller/trade/detail?order_id='.$order['order_id'])}}" class="link" target="_blank">订单详情</a></p>
                            @if ($order['buyer_message'])
                                <p style="color: #f00;" role="button" data-toggle="tooltip" data-placement="bottom" data-html="true" data-title="{{$order['buyer_message']}}">备注</p>
                                @else
                                    <p style="color: #777;">备注</p>
                            @endif
                        @endif
                    </td>
                    <td class="col5">
                        @if ($loop->first)
                            <p><strong style="color: #FF0000;">￥{{$order['total_fee']}}</strong></p>
                            <p style="font-size: 11px;">(含运费:￥{{$order['shipping_fee']}})</p>
                        @endif
                    </td>
                    <td class="col7">
                        @if ($loop->first)
                            @if ($order['trade_status'] == 1)
                                @if (!$order->pay_underline)
                                    <a>
                                        <span class="btn btn-primary" onclick="payUnderLine({{$order['order_id']}})">线下支付</span>
                                    </a>
                                @endif
                            @elseif($order['trade_status'] == 2)
                                <p>
                                    <a href="{{url('/seller/trade/detail?order_id='.$order['order_id'])}}" target="_blank">
                                        <span class="btn btn-primary btn-sm">发货</span>
                                    </a>
                                </p>
                                <p>
                                    <a href="{{url('seller/kuaidi/print?order_no='.$order['order_no'])}}" target="_blank">
                                        打印面单
                                    </a>
                                </p>
                            @elseif($order['trade_status'] == 3)

                            @elseif($order['trade_status'] == 4)
                                {{--<p><a>评价买家</a></p>--}}
                            @elseif($order['trade_status'] == 5)
                                @if ($order['refund_status'] == 1 ||$order['refund_status'] == 3)
                                    <p>
                                        <a href="{{url('seller/trade/refund?order_id='.$order['order_id'])}}" target="_blank">
                                            <span class="btn btn-primary">处理退款</span>
                                        </a>
                                    </p>
                                @endif
                            @elseif($order['trade_status'] == 6)

                            @endif
                        @endif
                    </td>
                </tr>
                @endforeach
                </tbody>
            </table>
        </div>
        @endforeach
        <div class="bottom-actions">
            <div class="float-right">{!! $pagination !!}</div>
            <label><input type="checkbox" class="checkmark" data-action="checkall"> 全选</label>
        </div>
    </div>
    <script type="text/javascript">
        function payUnderLine(order_id) {
            // DSXUI.showConfirm('确认要将订单改为以支付状态?', function () {
            //     $.ajax({
            //         type:'POST',
            //         url:'/seller/trade/payunderline',
            //         data:{order_id:order_id},
            //         success:function (response) {
            //             DSXUtil.reFresh();
            //         },
            //         complete:function (xhr) {
            //             //alert(JSON.stringify(xhr));
            //         }
            //     });
            // });
            DSXUI.dialog({
                title:'请输入支付流水',
                content:'<div style="text-align: center;"><input class="form-control w300" id="pay_no"></div>',
                style:{
                    width:'350px'
                },
                onConfirm:function (dlg) {
                    var pay_no = $("#pay_no").val();
                    if (!pay_no)
                    {
                        DSXUI.error('请填写支付流水');
                        return false;
                    }

                    dlg.close();
                    $.ajax({
                        type:"POST",
                        url:'/seller/trade/payunderline',
                        data:{order_id:order_id, pay_no:pay_no},
                        success:function (response) {
                            if (response.errcode)
                            {
                                DSXUI.error(response.errmsg);
                            } else {
                                DSXUI.showToast('申请已提交', 1500, function () {
                                    DSXUtil.reFresh();
                                });
                            }
                        }
                    });
                }
            });
        }

        $("#search").on('click', function () {
            $("#searchForm").attr('action', '{{url('seller/trade/sold')}}')
                .attr('target', '_self').submit();
        });
        $("#export").on('click', function () {
            $("#searchForm").attr('action', '{{url('seller/trade/export')}}')
                .attr('target', '_self').submit();
        });
    </script>
@stop
